<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.util.*"%>
<%@ page import="java.net.URLEncoder"%>
<%@ include file="/WEB-INF/ibnms/common/jsCommonVariables.jsp"%>
<html>
    <head>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
        <title>个人工作区</title>
        <link href="<%=stylePath%>/css/portal.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" src="<%=application.getContextPath()%>/njs/jquery/jquery-1.4.4.min.js"></script>
        <script type="text/javascript" src="<%=application.getContextPath()%>/njs/jquery/jquery-ui-1.8.10.custom.min.js"></script>
        <script type="text/javascript" src="<%=tabPath%>/ui.js"></script>
        <script type="text/javascript" src="<%=application.getContextPath()%>/njs/ui/portal.js"></script>
        <script type="text/javascript" src="<%=tabPath%>/mainFrame.js"></script>
        <script type="text/javascript">
            function getPorlets(){
                var porlets = "";
                $("div.item-col").each(function(){
                    var items = "";
                    $(this).children("div.item").each(function(){
                        items += ",";
                        items += $(this).attr("id");
                    });
                    if(items.length>0){
                        items = items.substring(1);
                    }
                    porlets+=";" +items;
                });
                return porlets.substring(1);
            }
        </script>
        <%
            Map<String, Map> porletsMap = (Map) request.getAttribute("porletsMap");
            Map<String, String> userSetting = (Map) request.getAttribute("userSetting");
            Map<String, String> layout = (Map) request.getAttribute("layout");
        %>
        <style type="text/css">
            body{
                margin: 0;
            }
            .widget{
                height: 100%;
                margin-top: 10px;
            }
            .widget div.item-col{
                height: 100%;
                margin-left: 1%;
                float: left;
                display: block;
                position: relative;
            }
        </style>
    </head>
    <body>
        <div id="page-warp">
            <div class="widget">
                <%
                    String[] emptyStrArray = new String[]{};
                    String[] pcol = userSetting.get("PORLETS") == null ? emptyStrArray : userSetting.get("PORLETS").split(";");
                    String[] widths = layout.get("COLUMN_WIDTHS") == null ? emptyStrArray : layout.get("COLUMN_WIDTHS").split(",");
                    int columns = Integer.parseInt(layout.get("COLUMNS") == null ? "0" : layout.get("COLUMNS").trim());
                    String iframeresizescript = request.getRequestURL().substring(0, request.getRequestURL().lastIndexOf("/")) + "/portal/pages/iframeResizeScript.jsp";
                    int wpercent = 0;
                    //遍历列
                    for (int i = 0; i < columns; i++) {
                        if (i != columns - 1) {
                            wpercent += Integer.parseInt(widths[i].replace("%", ""));
                        }
                %>
                <div class="item-col" style="<%=((i == columns - 1) ? "padding-right:10px\\9;width:" + (100 - wpercent - columns * 1.5) + "%;width:auto\\9;" : "width:" + widths[i] + ";")%>">
                    <%
                        if (pcol.length > i) {
                            String[] pitem = pcol[i] == null ? emptyStrArray : pcol[i].split(",");
                            // 遍历各列中的模块
                            for (int j = 0; j < pitem.length; j++) {
                                if (pitem[j] != null && !"".equals(pitem[j])) {
                                    Map porlet = porletsMap.get(pitem[j].trim());
                                    if(porlet!=null){
	                                    String iframid = "ifram_" + porlet.get("PORLET_ID");
	                                    StringBuilder contentURL = new StringBuilder();
	                                    contentURL.append(porlet.get("CONTENT_URL"));
	                                    contentURL.append(contentURL.indexOf("?") > 0 ? "&" : "?");
	                                    contentURL.append("iframeresizescript=").append(URLEncoder.encode(iframeresizescript + "?iframe_id=" + iframid, "utf8"));
	                                
                    %>
                    <div id="<%=porlet.get("PORLET_ID")%>" class="item">
                        <div class="caption" style="cursor: move">
                            <div class="text"><%=porlet.get("TITLE")%></div>
                            <div class="option">
                                <a href="javascript:;" class="min"></a>
                                <a href="javascript:;" class="max"></a>
                                <%if (!"1".equals(porlet.get("OBLIGED"))) {%><a href="javascript:;" class="close"></a><%}%>
                            </div>
                        </div>
                        <div class="content">
                            <iframe align="top" id='<%=iframid%>' name='<%=iframid%>' frameborder="0" 
                                    scrolling="no" src='<%=contentURL%>' width="100%" height='<%=porlet.get("HEIGHT")%>'>
                            </iframe>
                        </div>
                    </div>
                    <%          	}
                    			}
                            }
                        }
                    %>
                </div>
                <%
                    }
                %>
                <div class="clear"></div>
            </div>
        </div>
    </body>
</html>

